package competition;

import java.math.BigInteger;
import java.util.TreeSet;

/**
 * @BelongsProject: LeetCode
 * @BelongsPackage: competition
 * @Author: 江岸
 * @CreateTime: 2021-05-02 10:29
 * @Description:
 */
public class Week239 {
    public int getMinDistance(int[] nums, int target, int start) {
        TreeSet<Integer> treeSet = new TreeSet<>();
        for(int i=0;i<nums.length;i++){
            if(nums[i]==target) treeSet.add(i);
        }
        Integer higher = treeSet.floor(start);
        Integer ceiling = treeSet.ceiling(start);
        int res = Integer.MAX_VALUE;
        if (higher!=null) res = Math.abs(higher-start);
        if (ceiling!=null) res  = Math.min(res,Math.abs(ceiling-start));
        return res;
    }
 //050043
    public boolean splitString(String s) {
        while (s.length()!=0&&s.charAt(0)=='0'){//去前导0
            s = s.substring(1);
        }
        if (s.length()==1||s.length()==0) return false;
        for (int i=1;i<=s.length()/2+1;i++){//"99999999999999999999" 距离一半就行
            long n = Long.parseLong(s.substring(0, i));//"99999999999999999998"Long
            System.out.println("str"+n);
            boolean fun = fun(s.substring(i, s.length()), n);
            if (fun) return true;
        }
        return false;
    }

    public boolean fun(String s,long num){
        System.out.println("递归"+s);
        if (s.length()==0) return true;
        if (num==1&&Long.parseLong(s)==0) return true; //200100
        for (int i=1;i<=s.length();i++){
            long n = Long.parseLong(s.substring(0, i));
            if (n==num-1){
                return fun(s.substring(i,s.length()),n);
            }else if(n>=num){
                return false;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        boolean b = new Week239().splitString("0010");
        System.out.println(b);
    }
}
